define([
    'axios',
    "jquery",
    'jquery.cookie'
], function (axios, $){
    var getparams = function(url,json_params, srolid){
        let cookieValue = $.cookie('UserToken') || ''; // 获得cookie
         return new Promise(function(resolve) {
           axios.get(url,{params: json_params},{headers: {
            'Content-Type': 'application/json',   
            'Authorization':cookieValue
            }})
             .then(function (response) {
               var resValue = response || '';//JSON.stringify();
               resolve(resValue)
             })
             .catch(function (error) {
               var resValue = error.response || '';//JSON.stringify();
               resolve(resValue)
               //$(window).attr('location','login.html');
             });
         });
    };
    var get = function (url) {
        let s_url = url || '';
        let cookieValue = $.cookie('UserToken') || ''; // 获得cookie
        //alert("zzh---cookie:" + cookieValue);
        return new Promise(function(resolve) {
           // axios.defaults.headers['Authorization'] = base64.encode(cookieValue+'[&]'+srolid);
            axios.get(s_url,{headers: {
                'Authorization':cookieValue
            }})
            .then(function (response) {
                var resValue = response || '';//JSON.stringify();
                resolve(resValue)
            })
            .catch(function (error) {
                var resValue = error.response || '';//JSON.stringify();
                resolve(resValue)
                //$(window).attr('location','login.html');
            });
        });
    };
    var post = function(url,json_params, srolid){
        let cookieValue = $.cookie('UserToken') || ''; // 获得cookie
        return new Promise(function(resolve) {
            axios.post(url,json_params,{headers: {
                //'Content-Type': 'application/json',
                'Authorization':cookieValue
            }})
            .then(function (response) {
                console.log("response",response);
                var resValue = response || '';//JSON.stringify();
                resolve(resValue)
            })
            .catch(function (error) {
                console.log("error",error);
                var resValue = error.response || '';//JSON.stringify();
                resolve(resValue)
           //$(window).attr('location','login.html');
            });
        });
    };
    var put = function(url,json_params, srolid){
        let cookieValue = $.cookie('UserToken') || ''; // 获得cookie
        return new Promise(function(resolve) {
            axios.put(url,json_params,{headers: {
                //'Content-Type': 'application/json',
                'Authorization':cookieValue
            }})
            .then(function (response) {
                var resValue = response || '';//JSON.stringify();
                resolve(resValue)
            })
            .catch(function (error) {
                console.log(error);
                 var resValue = error.response || '';//JSON.stringify();
                resolve(resValue)
           //$(window).attr('location','login.html');
            });
        });
    };
    var del = function(url, srolid){
        let cookieValue = $.cookie('UserToken') || ''; // 获得cookie
        return new Promise(function(resolve) {
            axios.delete(url,{headers: {
                //'Content-Type': 'application/json',
                'Authorization':cookieValue
            }})
            .then(function (response) {
                var resValue = response || '';//JSON.stringify();
                resolve(resValue)
            })
            .catch(function (error) {
                console.log(error);
                 var resValue = error.response || '';//JSON.stringify();
                resolve(resValue)
           //$(window).attr('location','login.html');
            });
        });
    };

    var postfile = function(url,json_params, srolid){
        let cookieValue = $.cookie('UserToken') || ''; // 获得cookie
        return new Promise(function(resolve) {
            axios.post(url,json_params,{headers: {
                'Content-Type': 'multipart/form-data',
                'Authorization':cookieValue
            }})
            .then(function (response) {
                var resValue = response || '';//JSON.stringify();
                resolve(resValue)
            })
            .catch(function (error) {
                 var resValue = error.response || '';//JSON.stringify();
                resolve(resValue)
           //$(window).attr('location','login.html');
            });
        });
    };

    return {
        getparams:getparams,
        get:get,
        post:post,
        put:put,
        delete:del,
        postfile:postfile
    }
});